<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>管理员菜单</title>
    <link rel="stylesheet" type="text/css" href="../css/style.css"/>
    <link rel="stylesheet" type="text/css" href="../css/adminmenu.css"/>
</head>
<body style="background-color: #ffaa7f;">
<div>
    <div class="menu">
        <div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('adminMenu.html');">药品信息
                </button>
            </div>
        </div>
        <hr style="border: none;">
        <div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('visitInformation.html');">
                    就诊信息
                </button>
            </div>
            <div class="title" onclick="show(this)">
                <button style="width: 200px;font-size: 20px;" onclick="location.replace('expenseInformation.html');">
                    报销信息
                </button>
            </div>
            <div class="con hide">
            </div>
        </div>

    </div>
    <div id="drugs">
		<span style="padding: 0 0 520px 580px;">
		<button style="font-size: 20px;" onclick="location.replace('drugCreate.html')">新增药品</button>
		</span>
        <table>
            <thead>
            <tr>
                <th>药品编号</th>
                <th>药品名</th>
                <th>分类</th>
                <th>价格</th>
                <th>制造商</th>
                <th>执行操作</th>
            </tr>
            </thead>
            <tbody>
            <tr v-for="(item,index) in result.list">
                <td>{{item.drug_code}}</td>
                <td>{{item.drug_name}}</td>
                <td>{{item.drug_sort_name}}</td>
                <td>{{item.drug_price}}</td>
                <td>{{item.drug_producer}}</td>
                <td>
                    <button @click="updateDrug(item.drug_id)">修改</button>
                    <button @click="deleteDrug(item.drug_id)">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
        <div style="text-align:  center">
            <ul class="pagination" style="margin: auto;">
                <li v-for="n in result.pages">
                    <a href="javascript:void(0);" @click="search(n)" :class="{'active' : n==result.pageNum}">{{n}}</a>
                </li>
                <li>
                    <select @change="search(1)" v-model="searchParam.onePageCount">
                        <option v-for="item in pagecountlist" :value="item">{{item}}</option>
                    </select>
                </li>
            </ul>
        </div>
    </div>
</div>
</body>
<script src="http://code.jquery.com/jquery-latest.js"></script>

<script type="text/javascript" src="../js/axios.js"></script>
<script type="text/javascript" src="../js/vue.js"></script>
<script type="text/javascript" src="../js/message.js"></script>
<script>
    var vue = new Vue({
        el: "#drugs",
        data: {
            "result": {
                "list": {}
            },
            "searchParam": {
                "currentpage": 1,
                "onePageCount": 5
            },
            "pagecountlist": [5, 10, 20, 30, 50],
            showmsg: {
                msginfo: "",
                classobject: {
                    msg: false,
                    success: false
                }
            }
        },
        mounted: function () {
            this.pageLoad();
        },
        methods: {
            search: function (currentpage) {
                this.showmsg.msginfo = "";
                this.searchParam.currentpage = currentpage;
                axios.post("http://localhost:8000/bracelet/release/api/getdrugpagerlist",
                    {
                        "pageNum": this.searchParam.currentpage,
                        "pageSize": this.searchParam.onePageCount
                    })
                    .then(res => {
                        this.result = res.data.result;

                    })
                    .catch(error => {
                        alert(error.errorMsg);
                    });
            },
            updateDrug: function (drug_id) {
                //sessionStorage.setItem("drugId",drug_id);
                location.replace("drugUpdate.html?drugId=" + drug_id);
            },
            deleteDrug: function (drug_id) {
                console.log("66");
                axios.post("http://localhost:8000/bracelet/release/api/deletedrug",
                    {
                        "drugId": drug_id
                    })
                    .then(res => {
                        if (res.data.result) {
                            alert("删除成功");
                            location.reload();
                        }
                    })
                    .catch(error => {
                        alert(error.errorMsg);
                    });
                location.reload();
            }

        },
        created: function () {
            // 数据初始化完成
            this.search(1);
        },
        mounted: function () {
            // 数据挂载DOM完成事件
        }
    });
</script>

</html>